﻿using MathNet.Numerics.Statistics;
using innovations.ml.core.models;

namespace innovations.ml.core
{
    public class FeatureNormalizer
    {
        public static void Normalize(IModel model)
        {
            // i set to 1, not zero so that the first column of ones is not normalized.
            for (int i = 1; i < model.X.ColumnCount; i++)
            {
                model.Mu[i] = Statistics.Mean(model.X.Column(i));
                model.Sigma[i] = Statistics.StandardDeviation(model.X.Column(i));
                for (int j = 0; j < model.X.RowCount; j++)
                {
                    model.X[j, i] = (model.X[j, i] - model.Mu[i]) / model.Sigma[i];
                }
            }
        }
    }
}
